<?php

namespace App\Http\Controllers\Api;

use App\Robot;
use App\Http\Controllers\Controller;

class RobotsController extends Controller
{
    public function getRobots()
    {
        $arr = [];
        $robot = Robot::all('logname', 'pwd')->toArray();
        foreach ($robot as $val) {
            array_push($arr, $this->getMessage('http://yd.zhizhentang.com/member/game/getuser.htm', $val));
        }
        $arr2 = [];
        foreach ($arr as $item) {
            if ($item->result->integral > 100) {
                array_push($arr2, $item);
            }
        }
                    return $arr2;
    }
    public function getMessage($url = '', $param = '')
    {
        if (empty($url) || empty($param)) {
            return false;
        }

        $postUrl = $url;
        $curlPost = $param;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl
        curl_close($ch);

        return json_decode($data);
    }
}
